ReactJS Up and Running by Stoyan Stefanov

ReactJS Up and Running by Stoyan Stefanov

Author:Stoyan Stefanov
Language: eng
Format: epub, mobi
Tags: COMPUTERS / Programming Languages / JavaScript
ISBN: 9781491931752
Publisher: O’Reilly Media
Published: 2015-07-01T16:00:00+00:00


// copy the data var data = this.state.data.slice();

Now the actual sorting done via a callback to the sort() method:

data.sort(function(a, b) { return a[column] > b[column]; });

And finally, setting the state with the new, sorted data:

this.setState({ data: data });

Now, when you click a header, the contents gets sorted alphabetically (Figure 3-3)

Figure 3-3. Sorting by book title

And this is it, you don’t have to touch the UI rendering, in the render() method you’ve already defined once and for all how the component should look like given some data. When the data changes, so does the UI but this is none of your concern anymore.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.